package com.example.test_demo.test;

import java.util.HashMap;

/**
 * @program: Demo
 * @description:
 * @author: yanghua
 * @create: 2021-01-21 14:51
 **/
public class WangGuangHui {
    public static void main(String[] args) {
        //System.out.println(solve("asdfg"));
//        String[] source={"a","b"};
//        boolean[] abcs = isIn("abc", source);
//        for (int i = 0; i < abcs.length; i++) {
//            System.out.println(abcs[i]);
//        }
        //System.out.println(chkParenthesis("(()())",7));
        //System.out.println(exchangeStr("asfdsfs",7,3));
        String a = "11010";
        String b = "111101";
        int result = toInt(a)*toInt(b);
        //System.out.println(Integer.toBinaryString(result));

        char[] c = a.toCharArray();
        int sum = 0;
        for(int i=0;i<c.length;i++) {
            if(c[i]=='1') {
                sum = sum +1*(1<<c.length-i-1);
            }
        }

        char[] c2 = b.toCharArray();
        int sum2 = 0;
        for(int i=0;i<c2.length;i++) {
            if(c2[i]=='1') {
                sum2 = sum2 +1*(1<<c2.length-i-1);
            }
        }
        System.out.println(Integer.toBinaryString(sum*sum2));
    }
    static int toInt(String str) {
        HashMap<String, String> map = new HashMap<>();
        char[] c = str.toCharArray();
        int sum = 0;
        for(int i=0;i<c.length;i++) {
            if(c[i]=='1') {
                sum = sum +1*(1<<c.length-i-1);
            }
        }
        return sum;
    }



    /*
    交换字符串的位置
     */
    public static String exchangeStr(String str,int a,int i){
        if (a<i){
            return "超边界";
        }
        String zuoStr=null;
        String youStr=null;
        zuoStr=str.substring(0,i+1);
        youStr=str.substring(i+1);
        return youStr+zuoStr;

    }


    /*
    判断字符串中是否还有需求的(())
     */
    public static boolean chkParenthesis(String str, int n) {
        // write code here
        int l = 0; //左括号数
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++)
        {
            char c = chars[i];
            if (c == '(') {
                l++;
            } else if (c == ')') {
                if (l > 0) {
                    l--;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
        return l == 0;
    }




    public static boolean[] isIn(String substring, String[] source) {
        boolean[] bs=new boolean[source.length];
        /*
        数组小于等于500
         */
        if (source == null || source.length == 0|| source.length >500) {
            return bs;
        }
        /*
        字符串长度小于等于1000
         */
        if (substring.length()>1000) {
            return bs;
        }

        for (int i = 0; i < source.length; i++) {
            String aSource = source[i];
            /*
            字符串数组中元素小于等于8
             */
            if (substring.contains(aSource)&&aSource.length()<9) {
                bs[i]=true;
            }else {
                bs[i]=false;

            }
        }
        return bs;
    }
    /**
     * 反转字符串
     * @param str string字符串
     * @return string字符串
     */
    public static String solve (String str) {
        // write code here
        String s ="";
        if(str == null ||str.length() == 0){
            return s;
        }
        return reserve(str);
    }

    private static String reserve(String str){
        char[] c = str.toCharArray();
        int i = 0 , j = c.length-1;
        char tmp =c[0];
        while(i < j){
            tmp = c[i];
            c[i] = c[j];
            c[j] = tmp;
            ++i;
            --j;
        }
        String s = String.copyValueOf(c);
        return s;
    }
}
